import { createI18n } from 'vue-i18n';

import zhCN from './customLocal/zhCN';
import zh_TW from './customLocal/zh_TW';
import enUS from './customLocal/enUS';

import setting from '@/settings/designSetting';
import { getFileNameNoTypeByPath } from '@/utils/lib/filePath';

const modules = import.meta.globEager('./customLocal/**/*.ts');

const messages = {};
Object.keys(modules).forEach((key) => {
  const mod = modules[key].default || {};
  const fileName = getFileNameNoTypeByPath(key);
  messages[fileName] = mod;
});

// 默认语言
// const langDefault = 'zh-CN'
const langDefault = setting.language;

export function getMessage(lang) {
  return messages[lang] ? messages[lang] : messages[langDefault];
}

const i18n = createI18n({
  locale: langDefault, //默认显示的语言
  messages,
});

export default i18n; // 将i18n暴露出去，在main.js中引入挂载

export { messages };
